import { GStatic } from "../../../Core/Manager/DataPool";

const { ccclass } = cc._decorator;
@ccclass
export class SStoryData extends GStatic {
    public parse(obj: any): boolean {
        for (let i = 0; i < obj.data.length; i++) {
            let raw = GStatic.addonRaw<SStoryDataRaw>(obj.data[i]);
            this._data.set(raw.id, raw);
        }
        return true;
    }

    public getStorysBySection(section: number): SStoryDataRaw[] {
        let arr = [];
        this._data.forEach((v: SStoryDataRaw) => {
            if (v.section === section) {
                arr.push(v);
            }
        })
        return arr;
    }


    public getSection() {
        let arr = [];
        let index = 1;
        let bool = false;
        this._data.forEach((v: SStoryDataRaw) => {
            if (v.section === index && !bool) {
                bool = true;
                arr.push(v.section);
                index++;
            } else {

                bool = false;
            }
        })
        return arr;
    }

    public getSnow() {
        let arr = [];
        let index = 0;
        let bool = false;
        this._data.forEach((v: SStoryDataRaw) => {
            if (v.snow != index && !bool) {
                bool = true;
                arr.push(v.snow);
                index = v.snow;
            } else {
                bool = false;
            }
        })
        return arr;
    }
}